package com.youxin.cpcenter.controller;

import java.util.Objects;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.youxin.cpcenter.common.log.LogMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.youxin.busfoundation.bean.wexin.WxOpenAccessTokenBean;
import com.youxin.busfoundation.bean.wexin.WxOpenUserInfoBean;
import com.youxin.busfoundation.utils.WexinUtils;
import com.youxin.cpcenter.bean.RequestWxOpenBean;
import com.youxin.cpcenter.common.Consts;

/**
 * 微信开放平台登录
 * @author yingde.cao
 *
 */
@RestController
public class WxPublicController {
	//, RequestWxOpenBean reqeustBean
	@LogMethod(id="ent.wxpublic.callback",eventContent={})
	@RequestMapping("/wxpublic/callback")
	public String wxPublicCallBack(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
//		String code=reqeustBean.getCode();
//		Objects.requireNonNull(code, "Code为空");
//		WxOpenAccessTokenBean accessTokenBean=WexinUtils.getOpenAccessToken(Consts.WX_OPEN_APPID, Consts.WX_OPEN_SECRET, code);
//		WxOpenUserInfoBean userInfoBean=WexinUtils.getOpenUserInfo(accessTokenBean.getAccessToken(), accessTokenBean.getOpenid());
		return "log";
	}

	@LogMethod(id="ent.wxpublic.login",eventContent={})
	@RequestMapping("/wxpublic/login")
	public String wxPublicLogin(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
		return "<script language=\"javascript\" type=\"text/javascript\">"+ 
"var tTime=new Date(). getTime();"+
"var url= encodeURIComponent('http://ujweng.s1.natapp.cc/wxopen/callback');"+
"window.location.href='https://open.weixin.qq.com/connect/qrconnect?appid="+Consts.WX_OPEN_APPID+"&redirect_uri='+url+'&response_type=code&scope=snsapi_login&state=3d6be0a4035d839573b04816624a415e#wechat_redirect"+
"';</script>";
	}
}
